package com.ruibang.glass.material.service.impl.lbyp;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.material.domain.req.ycl.MaterialInventoryReq;
import com.ruibang.glass.material.entity.lbyp.MaterialLBYPInventoryManagement;
import com.ruibang.glass.material.mapper.lbyp.GMaterialLBYPInventoryManagementMapper;
import com.ruibang.glass.material.service.lbyp.GMaterialLBYPInventoryManagementService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 原材料库存管理表 服务实现类
 * </p>
 *
 * @author mameng
 * @since 2024-04-01
 */
@Service
public class GMaterialLBYPInventoryManagementServiceImpl extends ServiceImpl<GMaterialLBYPInventoryManagementMapper, MaterialLBYPInventoryManagement> implements GMaterialLBYPInventoryManagementService {
    /**
     * 列表
     * @param materialInventoryReq
     * @return
     */
    @Override
    public IPage<MaterialLBYPInventoryManagement> getPage(MaterialInventoryReq materialInventoryReq) {
        LambdaQueryWrapper<MaterialLBYPInventoryManagement> queryWrapper = Wrappers.<MaterialLBYPInventoryManagement>lambdaQuery();
        if (StringUtils.isNotBlank(materialInventoryReq.getMaterialCode())) {
            queryWrapper.like(MaterialLBYPInventoryManagement::getMaterialCode, materialInventoryReq.getMaterialCode());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getMaterialName())) {
            queryWrapper.like(MaterialLBYPInventoryManagement::getMaterialName, materialInventoryReq.getMaterialName());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getStorageLocation())) {
            queryWrapper.like(MaterialLBYPInventoryManagement::getStorageLocation, materialInventoryReq.getStorageLocation());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getSupplier())) {
            queryWrapper.like(MaterialLBYPInventoryManagement::getSupplier, materialInventoryReq.getSupplier());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getBatchNumber())) {
            queryWrapper.like(MaterialLBYPInventoryManagement::getBatchNumber, materialInventoryReq.getBatchNumber());
        }
        if (StringUtils.isNotBlank(materialInventoryReq.getBarcodeNumber())) {
            queryWrapper.like(MaterialLBYPInventoryManagement::getBarcodeNumber, materialInventoryReq.getBarcodeNumber());
        }

        Page<MaterialLBYPInventoryManagement> materialWarehouseInfoPage = baseMapper.selectPage(new Page<>(materialInventoryReq.getPageNo(), materialInventoryReq.getPageSize()),
                queryWrapper.orderByDesc(MaterialLBYPInventoryManagement::getCreateTime)
        );
        return materialWarehouseInfoPage;

    }
}
